home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / rcs / radio.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.7 KB  |  275 lines

  1. head    1.3;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.3; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.3
  10. date    97.09.17.08.16.41;    author dlorre;    state Exp;
  11. branches;
  12. next    1.2;
  13.  
  14. 1.2
  15. date    97.07.14.04.22.44;    author dlorre;    state Exp;
  16. branches;
  17. next    1.1;
  18.  
  19. 1.1
  20. date    96.08.22.02.05.10;    author dlorre;    state Exp;
  21. branches;
  22. next    ;
  23.  
  24.  
  25. desc
  26. @Oui.lib -- Object User Interface
  27. Projet créé en 1994
  28. Auteur: Dominique Lorre
  29. @
  30.  
  31.  
  32. 1.3
  33. log
  34. @tags used
  35. @
  36. text
  37. @// $Id: radio.cc 1.2 1997/07/14 04:22:44 dlorre Exp dlorre $
  38. #include <libraries/gadtools.h>
  39. #include <string.h>
  40. #include <stdio.h>
  41.  
  42. #include "gadgets/radio.h"
  43. #include "gadgetlist.h"
  44.  
  45. #include <proto/gadtools.h>
  46. #include <proto/utility.h>
  47.  
  48. // ========================================================================
  49. // ==========================  RADIO CLASS ================================
  50. // ========================================================================
  51.  
  52.  
  53. radio::radio(gadgetlist *gl,
  54.              void (window::*func)(gadget *, unsigned long, unsigned short),
  55.              TagItem *tags) :
  56.              gadget(gl, func), labsize(1), mxlabs(NULL)
  57. {
  58.     init(tags) ;
  59. }
  60. radio::radio(gadgetlist *gl,
  61.              void (window::*func)(gadget *, unsigned long, unsigned short),
  62.              ULONG tag1, ...) :
  63.              gadget(gl, func), labsize(1), mxlabs(NULL)
  64. {
  65.     init((TagItem *)&tag1) ;
  66. }
  67.  
  68. radio::~radio()
  69. {
  70.     if (mxlabs) {
  71.     int i ;
  72.         for (i=0; i<labsize; i++)
  73.             if (mxlabs[i]) delete mxlabs[i] ;
  74.         delete mxlabs ;
  75.     }
  76. }
  77.  
  78. void radio::init(TagItem *tags)
  79. {
  80. const char **p, **text = NULL ;
  81. const char *cp ;
  82. int i = 0 ;
  83. TagItem *t, *tl ;
  84.  
  85.     cursel = (LONG)GetTagData(ORADIO_Active, 0, tags) ;
  86.     glist->ng->ng_Flags = GetTagData(ORADIO_Flags, PLACETEXT_LEFT, tags) ;
  87.     spacing = (LONG)GetTagData(ORADIO_Spacing, 2, tags) ;
  88.  
  89.     if (FindTagItem(ORADIO_TextArray, tags)) {
  90.         text = p = (const char **)GetTagData(ORADIO_TextArray, NULL, tags) ;
  91.         cp = *p++ ;
  92.         while (cp) {
  93.             labsize++ ;
  94.             cp = *p++ ;
  95.         }
  96.      }
  97.     else {
  98.         tl = tags ;
  99.         while (t = NextTagItem(&tl)) {
  100.             if (t->ti_Tag == ORADIO_Text) {
  101.                 labsize++ ;
  102.             }
  103.         }
  104.         mxlabs = new STRPTR[labsize] ;
  105.         tl = tags ;
  106.         while (t = NextTagItem(&tl)) {
  107.             if (t->ti_Tag == ORADIO_Text) {
  108.                 cp = (const char *)GetTagData(ORADIO_Text, NULL, t) ;
  109.                 mxlabs[i] = new char[strlen(cp)+1] ;
  110.                 strcpy(mxlabs[i++], cp) ;
  111.             }
  112.         }
  113.         mxlabs[i] = NULL ;
  114.     }
  115.     if ((glist->top+(labsize-1)*(glist->height+spacing) - spacing) > glist->maxh)
  116.         glist->maxh = (WORD)glist->top + (labsize-1)*(glist->height+spacing) - spacing ;
  117.  
  118.     gad = glist->gad = CreateGadget(MX_KIND, glist->gad, glist->ng,
  119.             GTMX_Labels,    mxlabs ? mxlabs : text,
  120.             GTMX_Active,    cursel,
  121.             GTMX_Spacing,   spacing,
  122.             GTMX_Scaled,    TRUE,
  123.             GT_Underscore,  '_',
  124.             TAG_END) ;
  125. }
  126.  
  127.  
  128. void radio::action(unsigned long classe, unsigned short code)
  129. {
  130.     cursel = code ;
  131.     curstring = mxlabs[cursel] ;
  132.     gadget::action(classe, code) ;
  133. }
  134.  
  135. void radio::keystroke(BOOL shifted)
  136. {
  137.     if (shifted) {
  138.         cursel-- ;
  139.         if (cursel < 0) cursel=labsize-2 ;
  140.     }
  141.     else {
  142.         cursel++ ;
  143.         if (cursel > (labsize-2))
  144.             cursel = 0 ;
  145.     }
  146.     GT_SetGadgetAttrs(gad, w, NULL,
  147.         GTMX_Active,    cursel,
  148.         TAG_DONE) ;
  149.     curstring = mxlabs[cursel] ;
  150.     gadget::action(NULL, cursel) ;
  151. }
  152.  
  153.  
  154.  
  155. @
  156.  
  157.  
  158. 1.2
  159. log
  160. @*** empty log message ***
  161. @
  162. text
  163. @d1 1
  164. a1 1
  165. // $Id$
  166. d10 1
  167. d16 8
  168. d26 2
  169. a27 2
  170.              long active, unsigned long flags, long spacing,
  171.              const char **text) : gadget(gl, func), labsize(1), mxlabs(NULL)
  172. d29 2
  173. a30 2
  174. const char **p = text ;
  175. const char *cp ;
  176. d32 7
  177. a38 4
  178.     cp = *p++ ;
  179.     while (cp) {
  180.         labsize++ ;
  181.         cp = *p++ ;
  182. a39 13
  183.     cursel = active ;
  184.  
  185.     if ((gl->top+(labsize-1)*(gl->height+spacing) - spacing) > gl->maxh)
  186.         gl->maxh = gl->top + (labsize-1)*(gl->height+spacing) - spacing ;
  187.  
  188.     gl->ng->ng_Flags = flags ;
  189.     gad = gl->gad = CreateGadget(MX_KIND, gl->gad, gl->ng,
  190.             GTMX_Labels,    text,
  191.             GTMX_Active,    active,
  192.             GTMX_Spacing,   spacing,
  193.             GTMX_Scaled,    TRUE,
  194.             GT_Underscore,  '_',
  195.             TAG_END) ;
  196. d42 1
  197. a42 4
  198. radio::radio(gadgetlist *gl,
  199.              void (window::*func)(gadget *, unsigned long, unsigned short),
  200.              long active, unsigned long flags, long spacing,
  201.              const char *t, ...) : gadget(gl, func), labsize(1), mxlabs(NULL)
  202. d44 1
  203. a44 1
  204. const char **p = &t ;
  205. d47 5
  206. d53 2
  207. a54 3
  208.     cp = *p++ ;
  209.     while (cp) {
  210.         labsize++ ;
  211. d56 22
  212. d79 2
  213. a80 14
  214.     mxlabs = new STRPTR[labsize] ;
  215.     p = &t ;
  216.     cp = *p++ ;
  217.     while (cp) {
  218.         mxlabs[i] = new char[strlen(cp)+1] ;
  219.         strcpy(mxlabs[i++], cp) ;
  220.         cp = *p++ ;
  221.     }
  222.     mxlabs[i] = NULL ;
  223.  
  224.     cursel = active ;
  225.  
  226.     if ((gl->top+(labsize-1)*(gl->height+spacing) - spacing) > gl->maxh)
  227.         gl->maxh = gl->top + (labsize-1)*(gl->height+spacing) - spacing ;
  228. d82 3
  229. a84 4
  230.     gl->ng->ng_Flags = flags ;
  231.     gad = gl->gad = CreateGadget(MX_KIND, gl->gad, gl->ng,
  232.             GTMX_Labels,    mxlabs,
  233.             GTMX_Active,    active,
  234. a90 9
  235. radio::~radio()
  236. {
  237.     if (mxlabs) {
  238.     int i ;
  239.         for (i=0; i<labsize; i++)
  240.             if (mxlabs[i]) delete mxlabs[i] ;
  241.         delete mxlabs ;
  242.     }
  243. }
  244. @
  245.  
  246.  
  247. 1.1
  248. log
  249. @Initial revision
  250. @
  251. text
  252. @d1 1
  253. d9 1
  254. a9 1
  255. #include <cxxproto/gadtools.h>
  256. d18 1
  257. a18 1
  258.              STRPTR *text) : gadget(gl, func), labsize(1), mxlabs(NULL)
  259. d20 2
  260. a21 2
  261. STRPTR *p = text ;
  262. STRPTR  cp ;
  263. d46 1
  264. a46 1
  265.              STRPTR t, ...) : gadget(gl, func), labsize(1), mxlabs(NULL)
  266. d48 2
  267. a49 2
  268. STRPTR *p = &t ;
  269. STRPTR  cp ;
  270. d84 6
  271. a89 1
  272.     if (mxlabs) delete [] mxlabs ;
  273. d116 1
  274. @
  275.